#ifndef YHAIDA_ASYNCLOGGING_H
#define YHAIDA_ASYNCLOGGING_H
#include "../mutex/MutexLock.h"
#include "../mutex/Condition.h"
#include "../thread/CountDownLatch.h"
#include "../thread/Thread.h"
#include "../base/Utils.h"
#include "../datetime/Timestamp.h"
#include "LogFile.h"
#include <vector>
#include <memory>
#include <string>
namespace yhaida
{
    class AsyncLogging : Utils::nocapyable
    {
    public:
        typedef Detail::FixedBuffer<Detail::kLargeBuffer> Buffer;
        typedef std::unique_ptr<Buffer> BufferPtr;
        typedef std::vector<std::unique_ptr<Buffer>> BufferVector;

    public:
        // AsyncLogging()=default;
        AsyncLogging(const std::string &_baseName,
                     off_t _rollSize,
                     int _flushInterval=3);
        ~AsyncLogging();

        void push_logger(const char* str ,int length);
        void start(); //开线程
        void stop();  //关线程
    private:
        void threadFunc();

        std::atomic_bool _start;

        const std::string _baseName;
        const off_t _rollSize;
        const int _flushInterval;

        Thread _thread;
        MutexLock _mutex;
        Condition _cv;
        CountDownLatch _latch;

        BufferPtr _A_Buffer;
        BufferPtr _B_Buffer;
        BufferVector _bufferVector;
    };

}

#endif